home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
4_0
/
STANDALO
/
BELCH!_P
/
ASNDPLAY.C
next >
Wrap
Text File
|
1990-08-21
|
5KB
|
185 lines
/* ###################################################################
MODIFICATIONS MADE BY ANDREW WELCH:
This Asynch sound unit was designed to work from within an application.
In order to make it work from within a code resource, I had to make
minor modifications to it.
In the callback routine, this unit set up A5 so that it could
reference the static variable gSndPlaying. Well in code resources,
THINK C references static variables off of register A4, not A5 so
I had to find an alternative method to find and set the gSndPlaying
flag.
The method I chose should work from within a code resource, OR an
application. I simply remember the address of the global gSndPlaying
and reference that address directly. No need to remember/setup any
registers.
My thanks and appologies (because I changed his code around) to
Robert L Mathews for this THINK C Asynch sound unit.
################################################################### */
/*===========================================================
File: ASndPlayer ⌐1990 by Robert L Mathews / L Products
Plays asynchronous sounds when given a 'snd ' handle.
Based upon a Pascal source example by Larry Rosenstein
of Apple Computer, Inc.
History:
1.0 2/04/90 original version
1.1 2/08/90 fixed callback bug, added code to
allow waiting until previous sound
is finished
1.2 2/09/90 fixed multifinder bug - SndTask now
adds a callBackCmd (as well it should)
1.3 2/20/90 Figured out correct way to call A5 routines
Removed callBackCmd from SndTask
===========================================================*/
#include <SoundMgr.h>
/*=========================================================*/
void AInitSnd (void);
OSErr ASndPlay (Handle,Boolean);
void AStopSnd (Boolean);
Boolean SndIsPlaying (void);
void SndTask (void);
pascal void CallBack (SndChannelPtr,SndCommand*);
static SndChannelPtr gSndChannel;
static Boolean gSndPlaying;
static SndCommand myCommand;
/* CHANGE MADE BY ANDREW WELCH: */
typedef Boolean *BooleanPtr;
/* END OF CHANGES */
/*=========================================================*/
#define TRUE 1
#define FALSE 0
#define NIL 0
/*=========================================================*/
/* AInitSnd should be called as the program starts up */
void AInitSnd (void)
{
gSndChannel = 0;
gSndPlaying = FALSE;
}
/*=========================================================*/
/* SndIsPlaying returns TRUE if a snd is in progress */
Boolean SndIsPlaying (void)
{
return ( gSndPlaying);
}
/*=========================================================*/
/* CallBack marks the sound as done for use by SoundTask */
pascal void CallBack (tempChannel, tempCmd)
SndChannelPtr tempChannel;
SndCommand *tempCmd;
{
/* CHANGE MADE BY ANDREW WELCH: */
BooleanPtr flag;
flag=(BooleanPtr)tempCmd->param2;
(*flag)=FALSE;
/* END OF CHANGES */
}
/*=========================================================*/
/* SndTask disposes the channel if necessary (so other */
/* applications running can use the Sound Manager). */
void SndTask (void)
{
if (gSndChannel != 0 && gSndPlaying == FALSE)
{
SndDisposeChannel (gSndChannel, TRUE);
gSndChannel = 0;
}
}
/*=========================================================*/
/* ASndPlay is the async version of SndPlay, pass a handle */
/* to a 'snd ' resource. If stopPrev is TRUE, it stops */
/* any sound that may already be playing. Otherwise, it */
/* takes control of the computer until the first sound is */
/* done (aka synchronous sound playing), and then plays */
/* the second sound asynchronously. */
OSErr ASndPlay (mySndHandle, stopPrev)
Handle mySndHandle;
Boolean stopPrev;
{
OSErr err = noErr;
AStopSnd( stopPrev);
err = SndNewChannel( &gSndChannel, 0, 0, CallBack);
if (err == noErr)
{
err = SndPlay (gSndChannel, mySndHandle, FALSE);
if (err == noErr)
{
gSndPlaying = TRUE;
myCommand.cmd = callBackCmd;
/* CHANGE MADE BY ANDREW WELCH: */
myCommand.param2 = (long)&gSndPlaying;
/* END OF CHANGES */
err = SndDoCommand (gSndChannel, &myCommand, FALSE);
}
}
return (err);
}
/*=========================================================*/
/* AStopSnd stops an asyncronous sound from playing. */
/* It also must be called at the end of the program. */
/* If stopNow is TRUE, it stops the current sound immed- */
/* iately. Otherwise, it waits (here) until the sound */
/* is finished playing, then exits. */
void AStopSnd (stopNow)
Boolean stopNow;
{
SndDisposeChannel (gSndChannel, stopNow);
gSndChannel = 0;
gSndPlaying = FALSE;
}